/**
 * @Title: StockDaykInfoContorller.java
 * @Package cn.com.klun.tjy.controller
 * @Description: TBL_STOCK_DAYK_INFO的控制器
 * @author GOME
 * @date Mon Jan 15 18:08:07 CST 2018
 * @company cn.com.gome
 * @version V1.0
 */

package cn.com.klun.tjy.admin.controller;

import cn.com.klun.tjy.admin.common.AbstractAdminController;
import cn.com.klun.tjy.admin.common.EntityPersistenceLayerService;
import cn.com.klun.tjy.common.baseInterface.PersistenceLayerSerMapper;
import cn.com.klun.tjy.common.basePojo.PageQueryEntitys;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.ui.Model;
import java.util.List;
import cn.com.klun.tjy.dao.entity.TblStockDaykInfo;
import cn.com.klun.tjy.vo.StockDaykInfoVo;
import cn.com.klun.tjy.dao.mapper.edit.TblStockDaykInfoEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblStockDaykInfoSerMapper;

/**
 * @ClassName: StockDaykInfoContorller
 * @Description: TBL_STOCK_DAYK_INFO的控制器
 * @author GOME
 * @date 2015年2月10日 下午2:35:34
 */
@Controller
@RequestMapping("/stockdaykinfo")
public class StockDaykInfoController extends AbstractAdminController {

	@Autowired
	private EntityPersistenceLayerService entityPersistenceLayerService;

	@Autowired
	private TblStockDaykInfoEditMapper tblStockDaykInfoEditMapper;

	@Autowired
	private TblStockDaykInfoSerMapper tblStockDaykInfoSerMapper;

	@RequestMapping("/inits")
	public String init(Model model,HttpServletRequest request, HttpServletResponse response) {

		return "stockdaykinfo/inits";
	}

	@RequestMapping("/search")
	public void search(@ModelAttribute("pageQueryEntitys") PageQueryEntitys pageQueryEntitys, HttpServletRequest request, HttpServletResponse response) {
		try {
			pageQueryEntitys.setEntityClassName("TblStockDaykInfo");
			String kId = request.getParameter("kId");
			if (StringUtils.isNotEmpty(kId)) {
				pageQueryEntitys.addF("kId", kId);
			}
			String stoId = request.getParameter("stoId");
			if (StringUtils.isNotEmpty(stoId)) {
				pageQueryEntitys.addF("stoId", stoId);
			}
			String trnDate = request.getParameter("trnDate");
			if (StringUtils.isNotEmpty(trnDate)) {
				pageQueryEntitys.addF("trnDate", trnDate);
			}
			String starPri = request.getParameter("starPri");
			if (StringUtils.isNotEmpty(starPri)) {
				pageQueryEntitys.addF("starPri", starPri);
			}
			String maxPri = request.getParameter("maxPri");
			if (StringUtils.isNotEmpty(maxPri)) {
				pageQueryEntitys.addF("maxPri", maxPri);
			}
			String minPri = request.getParameter("minPri");
			if (StringUtils.isNotEmpty(minPri)) {
				pageQueryEntitys.addF("minPri", minPri);
			}
			String endPri = request.getParameter("endPri");
			if (StringUtils.isNotEmpty(endPri)) {
				pageQueryEntitys.addF("endPri", endPri);
			}
			String trnNum = request.getParameter("trnNum");
			if (StringUtils.isNotEmpty(trnNum)) {
				pageQueryEntitys.addF("trnNum", trnNum);
			}
			String trnAmount = request.getParameter("trnAmount");
			if (StringUtils.isNotEmpty(trnAmount)) {
				pageQueryEntitys.addF("trnAmount", trnAmount);
			}
			String lockFlag = request.getParameter("lockFlag");
			if (StringUtils.isNotEmpty(lockFlag)) {
				pageQueryEntitys.addF("lockFlag", lockFlag);
			}
			String lockTime = request.getParameter("lockTime");
			if (StringUtils.isNotEmpty(lockTime)) {
				pageQueryEntitys.addF("lockTime", lockTime);
			}
			String lockCounts = request.getParameter("lockCounts");
			if (StringUtils.isNotEmpty(lockCounts)) {
				pageQueryEntitys.addF("lockCounts", lockCounts);
			}
			String taskUpdateTime = request.getParameter("taskUpdateTime");
			if (StringUtils.isNotEmpty(taskUpdateTime)) {
				pageQueryEntitys.addF("taskUpdateTime", taskUpdateTime);
			}
			pageQueryEntitys = entityPersistenceLayerService.queryPageVoList((PersistenceLayerSerMapper) tblStockDaykInfoSerMapper, pageQueryEntitys);
		} catch (Exception e) {
			logger.error(" TBL_STOCK_DAYK_INFO的控制器执行异常【search】",e);
		}
		ajaxJsonPage(JSONArray.fromObject(pageQueryEntitys.getList()).toString(),pageQueryEntitys.getTotalCount(),response);
	}

	@RequestMapping("/select")
	public void select(HttpServletRequest request, HttpServletResponse response) {
		try {
			TblStockDaykInfo obj = new TblStockDaykInfo();
			List<TblStockDaykInfo> list = tblStockDaykInfoSerMapper.queryList(obj);
			ajaxJsonMessage(response,JSONArray.fromObject(list).toString());
		} catch (Exception e) {
			logger.error(" TBL_STOCK_DAYK_INFO的控制器执行异常【select】",e);
		}
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request, HttpServletResponse response,Model model){
		model.addAttribute("resultType", "add");
		return "stockdaykinfo/add";
	}

	@RequestMapping("/save")
	public String save(@ModelAttribute("enitty") TblStockDaykInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			tblStockDaykInfoEditMapper.save(enitty);
			model.addAttribute("messages", "温馨提示：添加成功！");
			model.addAttribute("resultStatus", "true");
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：添加异常:" + e.getMessage());
			logger.error(" stockdaykinfo的控制器执行异常【save】",e);
		}
		model.addAttribute("ADN_ADD_URL", "stockdaykinfo/add.dhtml");
		return "success";

	}

	@RequestMapping("/query")
	public String query(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "edit");
			model.addAttribute("resultStatus", "false");
			TblStockDaykInfo enitty = new TblStockDaykInfo();
			enitty.setKId(Integer.valueOf(request.getParameter("id_key")));
			enitty = (TblStockDaykInfo) tblStockDaykInfoSerMapper.queryObj(enitty);
			if (enitty != null){
				model.addAttribute("enitty", enitty);
				model.addAttribute("resultStatus", "true");
				return "stockdaykinfo/add";
			}
			model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");

		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" stockdaykinfo的控制器执行异常【query】",e);
		}
		return "success";
	}

	@RequestMapping("/edit")
	public String edit(@ModelAttribute("enitty") TblStockDaykInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblStockDaykInfoEditMapper.edit(enitty);
			if (count == 0) {
				model.addAttribute("messages", "温馨提示：修改失败！");
			} else {
				model.addAttribute("messages", "温馨提示：修改成功！");
				model.addAttribute("resultStatus", "true");
				TblStockDaykInfo enittyNew = new TblStockDaykInfo();
				enittyNew.setKId(enitty.getKId());
				enittyNew = (TblStockDaykInfo) tblStockDaykInfoSerMapper.queryObj(enittyNew);
				model.addAttribute("enitty", enittyNew);
				model.addAttribute("resultStatus", "true");
				model.addAttribute("resultType", "edit");
				return "stockdaykinfo/add";
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：修改异常:" + e.getMessage());
			logger.error(" stockdaykinfo的控制器执行异常【edit】",e);
		}
		return "success";
	}

	@RequestMapping("/del")
	public void del(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblStockDaykInfoEditMapper.del(Arrays.asList(request.getParameter("id_key").split(",")));
			if (count == 0) {
				ajaxJsonMessage(response,"0002","温馨提示：没有删除到符合条件的记录！","");
			} else {
				ajaxJsonMessage(response,"0000","温馨提示：删除成功！","");
			}
		} catch (Exception e) {
			ajaxJsonMessage(response,"0002","温馨提示：删除失败！","");
			logger.error(" stockdaykinfo的控制器执行异常【del】",e);
		}
	}

	@RequestMapping("/view")
	public String view(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "view");
			model.addAttribute("resultStatus", "false");
			TblStockDaykInfo enitty = new TblStockDaykInfo();
			enitty.setKId(Integer.valueOf(request.getParameter("id_key")));
			StockDaykInfoVo vo = (StockDaykInfoVo) tblStockDaykInfoSerMapper.queryVo(enitty);
			if (vo != null){
				model.addAttribute("enitty", vo);
				model.addAttribute("resultStatus", "true");
			}else{
				model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" stockdaykinfo的控制器执行异常【view】",e);
		}
		return "stockdaykinfo/add";
	}

}
